%% Parameters
% Lab-PC
% filename = 'D:\Server\FTP_server\Temp\origianl_maritx_01.fid\fid'
% filename = 'D:\Server\FTP_server\20130930_KSJ_CSI2D_test01\8by8M_20by50F_Water_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131009_KSJ_NAA_CSI2D_RatBrainCoil01\origianl_maritx_volCoil_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131015_KSJ_CSI2D_Gly_Cr_NAA_50mM_Phantom01\16by8M_35by20F_TR4s_2gain_Water_SatBand_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131009_KSJ_NAA_CSI2D_RatBrainCoil01\origianl_maritx_volCoil_sqaure_01.fid\fid'
filename = 'D:\Server\FTP_server\20131015_KSJ_CSI2D_Gly_Cr_NAA_50mM_Phantom01\8by8M_16by16F_TR4s_2gain_Water_SatBand_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131015_KSJ_CSI2D_Gly_Cr_NAA_50mM_Phantom01\8by8M_16by16F_TRmin_2gain_ZeroFlipAngle_NoSat_01.fid\fid'

% get header information.
cell_args = {3}; % default value; display nothing
[reference, headerinfo] = readfidn(filename, 1, 1, cell_args);

nblocks=headerinfo{1, 1}(1) % header info
ntraces=headerinfo{1, 1}(2) % status info
dataP=headerinfo{1, 1}(3)/2; % data points
channel = 4;

% real part
c_args = {3};

figure(1);
plot(real(fftshift(fft(reference))));
snr = zeros(ntraces, nblocks);

for indx_trace = 1:1:ntraces
    for indx_block = 1:1:nblocks
        % read  a fid
        arr_fid = readfidn(filename, indx_block, indx_trace, cell_args);
        arr_spectrum = fftshift(fft(arr_fid));

        % Pick up a peak
        [snr(indx_trace, indx_block) indx_peak] = mrsSNR(arr_spectrum, [2 501], 1, c_args);
    end
end

imagesc(snr);
colormap('gray');

% one transient
select_trace = 1;
for indx = 1:1:channel
    temp = readfidn(filename, indx, select_trace, {3});
    temp = fftshift(fft(temp));
    
    figure(2);
    if indx == 1
        plot(abs(temp),'blue');
    elseif indx == 2
        plot(abs(temp), 'red');
    elseif indx == 3
        plot(abs(temp), 'cyan');
    elseif indx == 4 
        plot(abs(temp), 'black');
    end
    hold on;
end

clear;